package algotithm.interview.去哪儿.test1;

import java.io.*;
import java.util.*;

/**
 * @author zhouyanxiang
 * @Date 2021-04-2021/4/12-18:04
第一行为一个整数N，表示数组的大小；

接下来N行，每行一个整数，表示数组的每一个元素；

接下来一行为整数K。
2
2
2
1

2
 */
public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        int n = Integer.parseInt(reader.readLine());
        int[] arr = new int[n];
        int t = n;
        int idx = 0;
        while (t-- > 0) {
            arr[idx++] = Integer.parseInt(reader.readLine());
        }
        int k = Integer.parseInt(reader.readLine());
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            map.put(arr[i],map.getOrDefault(arr[i],0) + 1);
        }
        List<Map.Entry<Integer,Integer>> list = new ArrayList<>(map.entrySet());
        Collections.sort(list, new Comparator<Map.Entry<Integer, Integer>>() {
            @Override
            public int compare(Map.Entry<Integer, Integer> o1, Map.Entry<Integer, Integer> o2) {
                if (!o1.getValue().equals(o2.getValue())) {
                    return o2.getValue() - o1.getValue();
                } else {
                    return o2.getKey() - o1.getKey();
                }
            }
        });
        int res = list.get(k - 1).getKey();
        writer.write(res + "\n");
        writer.flush();
        writer.close();
        reader.close();
    }

}
